//
//  AppSetting.m
//  SFA_Core
//
//  Created by Vergil on 2017/4/10.
//  Copyright © 2017年 Vergil. All rights reserved.
//

#import "AppSetting.h"
#import <SSKeychain/SSKeychain.h>

@interface AppSetting ()

@property (nonatomic, strong) NSUserDefaults *userDefaults;
@end

static AppSetting *appSetting = nil;

@implementation AppSetting

+ (instancetype)shareAppSetting {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        appSetting = [[AppSetting alloc] init];
        
    });
    return appSetting;
    
}

- (instancetype)init {
    
    if (self = [super init]) {
        _userDefaults = [NSUserDefaults standardUserDefaults];
    }
    return self;
    
}

#pragma mark - setting

- (void)setGetBasicMessage:(NSString *)getBasicMessage {
    [self.userDefaults setObject:getBasicMessage forKey:@"getBasicMessage"];
    [self.userDefaults synchronize];
}

- (void)setAccessToken:(NSString *)accessToken {
    [self.userDefaults setObject:accessToken forKey:ACCESS_TOKEN];
    [self.userDefaults synchronize];
}

- (void)setBaseUrlString:(NSString *)baseUrlString {
    [self.userDefaults setObject:baseUrlString forKey:@"BaseUrlString"];
    [self.userDefaults synchronize];
}

- (void)setPassWord:(NSString *)passWord userName:(NSString *)userName {
    [SSKeychain setPassword:passWord forService:SERVICENAME account:userName];
}

- (void)setIsLogin:(NSString *)isLogin {
    [self.userDefaults setObject:isLogin forKey:@"kIsLogin"];
    [self.userDefaults synchronize];
}

- (void)setSelStartIndex:(NSInteger)selStartIndex {
    [self.userDefaults setInteger:selStartIndex forKey:@"selStartIndex"];
    [self.userDefaults synchronize];
}

- (void)setTimeDuration:(NSInteger)timeDuration {
    [self.userDefaults setInteger:timeDuration forKey:@"timeDuration"];
    [self.userDefaults synchronize];
}

- (void)setTopcompanyid:(NSString *)topcompanyid {
    [self.userDefaults setObject:topcompanyid forKey:@"topcompanyid"];
    [self.userDefaults synchronize];
}
- (void)setUserid:(NSString *)userid {
    [self.userDefaults setObject:userid forKey:@"userid"];
    [self.userDefaults synchronize];
}
- (void)setMemberid:(NSString *)memberid {
    [self.userDefaults setObject:memberid forKey:@"memberid"];
    [self.userDefaults synchronize];
}
- (void)setTokenuserid:(NSString *)tokenuserid {
    [self.userDefaults setObject:tokenuserid forKey:@"tokenuserid"];
    [self.userDefaults synchronize];
}
- (void)setTokenid:(NSString *)tokenid {
    [self.userDefaults setObject:tokenid forKey:@"tokenid"];
    [self.userDefaults synchronize];
}


#pragma mark - getting

- (NSString *)getBasicMessage {
    return [self.userDefaults objectForKey:@"getBasicMessage"];
}

- (NSString *)accessToken {
    return [self.userDefaults objectForKey:ACCESS_TOKEN];
}

- (NSString *)baseUrlString {
    return [self.userDefaults objectForKey:@"BaseUrlString"];
}

- (NSString *)passwordForUserName:(NSString *)userName {
    return [SSKeychain passwordForService:SERVICENAME account:userName];
}

- (NSString *)isLogin {
    return [self.userDefaults objectForKey:@"kIsLogin"];
}

- (NSInteger)selStartIndex {
    return [self.userDefaults integerForKey:@"selStartIndex"];
}

- (NSInteger)timeDuration {
    return [self.userDefaults integerForKey:@"timeDuration"];
}

- (NSString *)topcompanyid {
    return [self.userDefaults objectForKey:@"topcompanyid"];
    
}
- (NSString *)userid {
    return [self.userDefaults objectForKey:@"userid"];
    
}
- (NSString *)memberid {
    return [self.userDefaults objectForKey:@"memberid"];
    
}
- (NSString *)tokenuserid {
    return [self.userDefaults objectForKey:@"tokenuserid"];
}
- (NSString *)tokenid {
    return [self.userDefaults objectForKey:@"tokenid"];
}


// MARK: - 退出登录---------------
- (void)logoOut {
    //取出所有的信息-----置空
    
}

// MARK: - 登录
- (void)loginIn {
    
}

@end
